﻿using GN.Pay.Utils;
using System;

namespace GN.Pay.TradeChannel.WeiXin.Response
{
    /// <summary>
    /// 支付响应
    /// </summary>
    [Serializable]
    abstract class PayResponse : AResponse
    {
        public PayResponse(string xml)
            : base(xml)
        {
        }

        /// <summary>
        /// 应用Id
        /// </summary>
        public string AppId { get; set; }

        /// <summary>
        /// 商户号
        /// </summary>
        public string Mch_Id { get; set; }

        /// <summary>
        /// 设备信息
        /// </summary>
        public string Device_Info { get; set; }

        /// <summary>
        /// 交易类型
        /// </summary>
        public string Trade_Type { get; set; }

        /// <summary>
        /// 支付id
        /// </summary>
        public string Prepay_Id { get; set; }

        /// <summary>
        /// 
        /// </summary>
        protected void ToResultCheck(WeiXinConfigure config)
        {
            if (!IsFullSuccess())
            {
                throw new InvalidOperationException("结果不成功，转换申请支付结果失败");
            }
            if (!SignVerify(config))
            {
                throw new InvalidOperationException("签名未通过，转换申请支付结果失败");
            }
        }

        /// <summary>
        /// 转为结果
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public abstract ITradePayApplyResult ToResult(WeiXinConfigure config);
    }
}
